import request from "@/utils/request";
import type { CategoryList } from "./model/categoryModel";

const enum API {
  category1List = "/admin/product/getCategory1",
  category2List = "/admin/product/getCategory2",
  category3List = "/admin/product/getCategory3",
  addCategory1 = "/admin/product/saveCategory1",
  addCategory2 = "/admin/product/saveCategory2",
  addCategory3 = "/admin/product/saveCategory3",
  updateCategory1 = "/admin/product/updateeCategory1",
  updateCategory2 = "/admin/product/updateeCategory2",
  updateCategory3 = "/admin/product/updateeCategory3",
  removeCategory1 = "/admin/product/removeCategory1",
  removeCategory2 = "/admin/product/removeCategory2",
  removeCategory3 = "/admin/product/removeCategory3",
}

/**
 * 一级分类
 * @returns
 */
export const getCategory1ListApi = () => {
  return request.get<any, CategoryList>(API.category1List);
};
/**
 * 二级分类
 * @returns
 */
export const getCategory2ListApi = (category1Id: number) => {
  return request.get<any, CategoryList>(API.category2List + `/${category1Id}`);
};
/**
 * 三级分类
 * @returns
 */
export const getCategory3ListApi = (category2Id: number) => {
  return request.get<any, CategoryList>(API.category3List + `/${category2Id}`);
};

// 添加一级分类
export const addCategory1Api = (name: string) => {
  return request.post<any, null>(API.addCategory1, { name });
};
// 添加二级分类
export const addCategory2Api = (name: string, category1Id: number) => {
  return request.post<any, null>(API.addCategory2, { category1Id, name });
};
// 添加三级分类
export const addCategory3Api = (name: string, category2Id: number) => {
  return request.post<any, null>(API.addCategory3, { category2Id, name });
};

// 更新一级分类
export const updateCategory1Api = (id: number, name: string) => {
  return request.put<any, null>(API.updateCategory1, { id, name });
};
// 更新二级分类
export const updateCategory2Api = (id: number, name: string) => {
  return request.put<any, null>(API.updateCategory2, { id, name });
};
// 更新三级分类
export const updateCategory3Api = (id: number, name: string) => {
  return request.put<any, null>(API.updateCategory3, { id, name });
};

// 删除一级分类
export const removeCategory1Api = (id: number) => {
  return request.delete<any, null>(API.removeCategory1 + `/${id}`);
};
// 删除二级分类
export const removeCategory2Api = (id: number) => {
  return request.delete<any, null>(API.removeCategory2 + `/${id}`);
};
// 删除三级分类
export const removeCategory3Api = (id: number) => {
  return request.delete<any, null>(API.removeCategory3 + `/${id}`);
};
